/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd. 		   */
/*																   */
/*	NAME	  = t__sqlserver_bigint_add.c						   */
/*	NOTE	  = 												   */
/*	DATE	  = 2014/11/25 by geyh								   */
/*******************************************************************/

#include <stdio.h>
#include <CUnit/Basic.h>

#include <postgresql/config.h>
#include <postgresql/postgresql_core.h>
#include <postgresql/postgresql_comm.h>

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_ret = FR_SUCC;
    unsigned long i_value = 0;
    i_ret = postgresql_atol((char *) "123rt", &i_value);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    return;
}

static void __case2(void)
{
    int i_ret = FR_SUCC;
    unsigned long i_value = 0;
    i_ret = postgresql_atol((char *) "-12", &i_value);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    return;
}

static void __case3(void)
{
    int i_ret = FR_SUCC;
    unsigned long i_value = 0;
    i_ret = postgresql_atol((char *) "12.1", &i_value);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    return;
}

static void __case4(void)
{
    int i_ret = FR_SUCC;
    unsigned long i_value = 0;
    i_ret = postgresql_atol((char *) "1", &i_value);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_value, 1);
    return;
}

static void __case5(void)
{
    int i_ret = FR_SUCC;
    unsigned long i_value = 0;
    i_ret = postgresql_atol((char *) "0011", &i_value);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_value, 11);
    return;
}

static void __case6(void)
{
    int i_ret = FR_SUCC;
    unsigned long i_value = 0;
    i_ret = postgresql_atol((char *) "", &i_value);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_value, 0);
    return;
}

int add_suite_postgresql_atol(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" postgresql_atol()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    //增加测试用例
    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL ||
        CU_add_test(pSuite, "case5", __case5) == NULL ||
        CU_add_test(pSuite, "case6", __case6) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
